#ifndef _DSWAX_AV_CLIENT_H
#define _DSWAX_AV_CLIENT_H
#include <libbase/dswtcpclient_base.h>

typedef void (*CB_AX_AV_CLIENT)(EN_MSG_TYPE nType, void* pParam0, void* pParam, void* pCaller);

class CDswax_av_client : public CDswtcpclient_base
{
public:
	CDswax_av_client(LPST_ENV_T pEnv, char* pHost, int nPort, CB_AX_AV_CLIENT pCBFunc, void* pCaller, char * pDevID, void* pParam);
	virtual ~CDswax_av_client();
public:
	void DestroyClient();
	void PostDestroyClient();
	static bool cbOnP2PReportIDV2(char* pCId, void* pMsgReq, const char* pMsgIDResp, void* pCaller){return ((CDswax_av_client*)pCaller)->OnP2PReportIDV2(pCId, pMsgReq, pMsgIDResp);};
private:
	bool OnP2PReportIDV2(char* pCId, void* pMsgReq, const char* pMsgIDResp);
	void SendMsg(char * pMsg);
	bool ProcessAVMsg(char* pMsg, int nLen, struct evbuffer *outbuf);
	bool ProcessTxtMsg(char* pMsg, int nLen, struct evbuffer *outbuf);
protected:
	virtual void OnConnect(struct bufferevent *bev, short events);
	virtual bool ProcessMessage(char* pMsg, int nLen, struct evbuffer *outbuf);
	virtual int MakePayloadLength(char* pData, int nLen){m_bIsMsg = (pData[0] == MSG_FLAG);return (pData[4] << 24 | pData[3] << 16 | pData[2] << 8 | pData[1]);};
	virtual void OnError(struct bufferevent * bev, short events);
private:
	CB_AX_AV_CLIENT m_pCBFunc;
	void *m_pCaller, *m_pParam;
	char m_sDevID[32], m_sPUCID[64];
	bool m_bIsMsg, m_bNeedReconnect, m_bValid;
	ST_DEVICE_BASE_T m_nBaseParam;
	time_t m_nAckTM;
};

#endif

